<template>
  <div class="users-page">
    <div class="page-header">
      <h2>用户管理</h2>
      <button class="btn-primary" @click="showAddUserModal = true">
        <span class="btn-icon">+</span>
        新增用户
      </button>
    </div>

    <!-- 用户列表组件 -->
    <UserList />

    <!-- 新增用户模态框 -->
    <AddUser
      :is-visible="showAddUserModal"
      @close="showAddUserModal = false"
      @success="handleUserAdded"
    />

    <!-- 成功消息提示 -->
    <div v-if="showSuccessMessage" class="success-message">
      <div class="message-content">
        <span class="success-icon">✅</span>
        <span>{{ successMessage }}</span>
      </div>
    </div>
  </div>
</template>

<script setup>
import { ref } from 'vue'
import { useUserStore } from '../stores/user'
import AddUser from '../components/AddUser.vue'
import UserList from '../components/UserList.vue'

const userStore = useUserStore()

// 响应式数据
const showAddUserModal = ref(false)
const showSuccessMessage = ref(false)
const successMessage = ref('')

// 处理用户添加成功
const handleUserAdded = (newUser) => {
  successMessage.value = `用户 "${newUser.name}" 添加成功！`
  showSuccessMessage.value = true
  
  // 3秒后隐藏成功消息
  setTimeout(() => {
    showSuccessMessage.value = false
  }, 3000)
}
</script>

<style scoped>
.users-page {
  animation: fadeIn 0.3s ease-in-out;
}

.page-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 30px;
}

.page-header h2 {
  color: #2c3e50;
  margin: 0;
  font-size: 28px;
}

.btn-primary {
  background: #3498db;
  color: white;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 500;
  transition: all 0.2s ease;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-primary:hover {
  background: #2980b9;
  transform: translateY(-1px);
}

.btn-icon {
  font-size: 16px;
  font-weight: bold;
}

.success-message {
  position: fixed;
  top: 20px;
  right: 20px;
  background: #d5f5e3;
  color: #27ae60;
  padding: 16px 20px;
  border-radius: 8px;
  border: 1px solid #a8e6cf;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  z-index: 1001;
  animation: slideInRight 0.3s ease-out;
}

.message-content {
  display: flex;
  align-items: center;
  gap: 8px;
}

.success-icon {
  font-size: 18px;
}

@keyframes fadeIn {
  from {
    opacity: 0;
    transform: translateY(20px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes slideInRight {
  from {
    opacity: 0;
    transform: translateX(100%);
  }
  to {
    opacity: 1;
    transform: translateX(0);
  }
}

@media (max-width: 768px) {
  .page-header {
    flex-direction: column;
    gap: 16px;
    align-items: stretch;
  }
  
  .success-message {
    top: 10px;
    right: 10px;
    left: 10px;
    max-width: none;
  }
}
</style> 